package api.dialogs;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JSeparator;

import api.Interface;
import api.components.DisplayHistogram;
import api.image.MyImage;
import javax.swing.JRadioButton;
import java.awt.Color;
import java.text.NumberFormat;

public class PropertiesDialog extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public JButton btnAceptar;
	public JLabel lblName;
	public JLabel lblExt;
	public JLabel lblTamIma;
	public JLabel lblRango;
	public JLabel lblBrill;
	public JLabel lblEntropia;
	public DisplayHistogram histogram;
	public JRadioButton rdbtnAbs;
	public JRadioButton rdbtnAcum;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			PropertiesDialog dialog = new PropertiesDialog();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public PropertiesDialog() {
		setModal(true);
		setTitle("Propiedades");
		setBounds(100, 100, 740, 386);
		getContentPane().setLayout(null);
		
		JPanel panelBtn = new JPanel();
		panelBtn.setBounds(6, 320, 728, 38);
		getContentPane().add(panelBtn);
		
		btnAceptar = new JButton("Aceptar");
		btnAceptar.setFont(new Font("Lucida Grande", Font.PLAIN, 11));
		panelBtn.add(btnAceptar);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(6, 6, 728, 308);
		getContentPane().add(tabbedPane);
		
		JPanel info = new JPanel();
		tabbedPane.addTab("Informacion", null, info, null);
		info.setLayout(null);
		
		JLabel lblNombre = new JLabel("Nombre:");
		lblNombre.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblNombre.setBounds(43, 70, 62, 16);
		info.add(lblNombre);
		
		JLabel lblTipo = new JLabel("Tipo de fichero:");
		lblTipo.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblTipo.setBounds(43, 130, 165, 16);
		info.add(lblTipo);
		
		JLabel lblTam = new JLabel("Tama\u00F1o de la imagen:");
		lblTam.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblTam.setBounds(43, 188, 165, 16);
		info.add(lblTam);
		
		JLabel lblTitulo = new JLabel("Informacion elemental de la imagen");
		lblTitulo.setFont(new Font("Lucida Grande", Font.BOLD, 14));
		lblTitulo.setBounds(221, 16, 276, 17);
		info.add(lblTitulo);
		
		MyImage image = Interface.getSelectedImage();
		
		lblName = new JLabel(image.name);
		lblName.setBounds(112, 70, 276, 16);
		info.add(lblName);
		
		lblExt = new JLabel(image.extension);
		lblExt.setBounds(158, 130, 276, 16);
		info.add(lblExt);
		
		lblTamIma = new JLabel(image.filas + " x " + image.cols + " Pixels");
		lblTamIma.setBounds(202, 188, 276, 16);
		info.add(lblTamIma);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(6, 34, 695, 16);
		info.add(separator);
		
		JPanel histograma = new JPanel();
		tabbedPane.addTab("Histograma", null, histograma, null);
		histograma.setLayout(null);
		
		rdbtnAbs = new JRadioButton("Absoluto");
		rdbtnAbs.setSelected(true);
		rdbtnAbs.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		rdbtnAbs.setBounds(0, 99, 109, 23);
		histograma.add(rdbtnAbs);
		
		rdbtnAcum = new JRadioButton("Acumulativo");
		rdbtnAcum.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		rdbtnAcum.setBounds(0, 152, 117, 23);
		histograma.add(rdbtnAcum);
		
		JSeparator separator_2 = new JSeparator();
		separator_2.setBounds(6, 33, 695, 16);
		histograma.add(separator_2);
		
		JLabel lblHistograma = new JLabel("Histograma");
		lblHistograma.setFont(new Font("Lucida Grande", Font.BOLD, 14));
		lblHistograma.setBounds(317, 17, 92, 17);
		histograma.add(lblHistograma);
		
		JPanel panelHistogram = new JPanel();
		panelHistogram.setBounds(116, 45, 585, 211);
		histograma.add(panelHistogram);
		
		histogram = new DisplayHistogram(image.histogram, "Absoluto");
		panelHistogram.add(histogram);
		
		JLabel lblLeyenda = new JLabel("Leyenda:");
		lblLeyenda.setFont(new Font("Lucida Grande", Font.BOLD, 11));
		lblLeyenda.setBounds(6, 197, 61, 16);
		histograma.add(lblLeyenda);
		
		JLabel lblNewLabel = new JLabel("Eje x: Nivel de gris");
		lblNewLabel.setForeground(Color.RED);
		lblNewLabel.setFont(new Font("Lucida Grande", Font.BOLD, 10));
		lblNewLabel.setBounds(16, 214, 121, 16);
		histograma.add(lblNewLabel);
		
		JLabel lblEjeY = new JLabel("Eje y: Frecuencia R.");
		lblEjeY.setForeground(Color.RED);
		lblEjeY.setFont(new Font("Lucida Grande", Font.BOLD, 10));
		lblEjeY.setBounds(16, 229, 99, 16);
		histograma.add(lblEjeY);
		
		JPanel avanzada = new JPanel();
		avanzada.setLayout(null);
		
		JLabel lblBrillo = new JLabel("Brillo:");
		lblBrillo.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblBrillo.setBounds(43, 80, 116, 16);
		avanzada.add(lblBrillo);
		
		JLabel lblEntro = new JLabel("Entropia:");
		lblEntro.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblEntro.setBounds(43, 160, 60, 16);
		avanzada.add(lblEntro);
		
		JLabel lblRango = new JLabel("Rango dinamico [min, max]:");
		lblRango.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblRango.setBounds(43, 200, 199, 16);
		avanzada.add(lblRango);
		
		NumberFormat NF = NumberFormat.getInstance();
		NF.setMaximumFractionDigits(2);
		
		lblBrill = new JLabel("" + NF.format(image.brillo));
		lblBrill.setBounds(90, 80, 273, 16);
		avanzada.add(lblBrill);
		
		lblEntropia = new JLabel("" + NF.format(image.entropia));
		lblEntropia.setBounds(115, 160, 273, 16);
		avanzada.add(lblEntropia);
		
		lblRango = new JLabel("[" + image.minGray + ", " + image.maxGray + "]");
		lblRango.setBounds(240, 200, 273, 16);
		avanzada.add(lblRango);
		
		JLabel lblTAvanzada = new JLabel("Informacion avanzada de la imagen");
		lblTAvanzada.setFont(new Font("Lucida Grande", Font.BOLD, 14));
		lblTAvanzada.setBounds(229, 16, 256, 17);
		avanzada.add(lblTAvanzada);
		
		tabbedPane.addTab("I. Avanzada", null, avanzada, null);
		
		JSeparator separator_1 = new JSeparator();
		separator_1.setBounds(6, 33, 695, 12);
		avanzada.add(separator_1);
		
		JLabel lblContraste = new JLabel("Contraste:");
		lblContraste.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		lblContraste.setBounds(42, 119, 72, 16);
		avanzada.add(lblContraste);
		
		JLabel lblcon = new JLabel("" + NF.format(image.contraste));
		lblcon.setBounds(120, 119, 273, 16);
		avanzada.add(lblcon);
	}
}
